package com.zy.openchat.core.manager;

import android.os.Parcel;
import android.os.Parcelable;

import com.zy.openchat.Constants;

import org.apache.commons.lang3.StringUtils;

import java.io.File;

public class AuthUserInfo implements Parcelable {
    public long userId;
    public String phone;
    public String data_directory;
    public long lastLoginTime;
    public boolean isCurrentLoginUser;

    public String data_directoryPath() {
        return Constants.authUserRootPath() + data_directory + File.separator;
    }

    public boolean isThisPhone(String other) {
        if (!StringUtils.isEmpty(other) && !StringUtils.isEmpty(phone)) {
            //正常比较
            if (other.equals(phone)) {
                return true;
            }
            //去除+号比较
            String phone1 = other;
            String phone2 = phone;
            if (phone1.startsWith("+")) {
                phone1 = phone1.substring(1);
            }
            if (phone2.startsWith("+")) {
                phone2 = phone2.substring(1);
            }
            if (phone1.equals(phone2)) {
                return true;
            }
            //去除0比较
            if (phone1.startsWith("0")) {
                phone1 = phone1.substring(1);
            }
            if (phone2.startsWith("0")) {
                phone2 = phone2.substring(1);
            }
            if (phone1.equals(phone2)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.userId);
        dest.writeString(this.phone);
        dest.writeString(this.data_directory);
        dest.writeLong(this.lastLoginTime);
        dest.writeByte(this.isCurrentLoginUser ? (byte) 1 : (byte) 0);
    }

    public AuthUserInfo() {
    }

    protected AuthUserInfo(Parcel in) {
        this.userId = in.readLong();
        this.phone = in.readString();
        this.data_directory = in.readString();
        this.lastLoginTime = in.readLong();
        this.isCurrentLoginUser = in.readByte() != 0;
    }

    public static final Creator<AuthUserInfo> CREATOR = new Creator<AuthUserInfo>() {
        @Override
        public AuthUserInfo createFromParcel(Parcel source) {
            return new AuthUserInfo(source);
        }

        @Override
        public AuthUserInfo[] newArray(int size) {
            return new AuthUserInfo[size];
        }
    };
}